package com.andaily.domain.dto.log;

import com.andaily.domain.dto.AbstractDTO;
import com.andaily.domain.dto.user.UserDto;
import com.andaily.domain.log.LogComment;
import com.andaily.domain.shared.DateUtils;
import com.andaily.domain.shared.security.SecurityUtils;

/**
 * @author Shengzhao Li
 */
public class LogCommentDto extends AbstractDTO {

    private String logGuid;
    private String content;
    private UserDto creator;
    private LogCommentDto parentLogComment;
    private String createDate;


    public LogCommentDto() {
    }

    public LogCommentDto(LogComment logComment) {
        this.guid = logComment.guid();
        this.logGuid = logComment.log().guid();
        this.content = logComment.content();
        this.createDate = DateUtils.toDateText(logComment.createTime());
        this.creator = new UserDto(logComment.creator());

        final LogComment parent = logComment.parentLogComment();
        if (parent != null) {
            this.parentLogComment = new LogCommentDto(parent);
        }
    }

    public boolean isAllowDelete() {
        return (SecurityUtils.isLogged()
                && SecurityUtils.currentUserGuid().equals(this.creator.getGuid()));
    }

    public String getCreateDate() {
        return createDate;
    }

    public void setCreateDate(String createDate) {
        this.createDate = createDate;
    }

    public LogCommentDto(String logGuid) {
        this.logGuid = logGuid;
    }

    public String getLogGuid() {
        return logGuid;
    }

    public void setLogGuid(String logGuid) {
        this.logGuid = logGuid;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public UserDto getCreator() {
        return creator;
    }

    public void setCreator(UserDto creator) {
        this.creator = creator;
    }

    public LogCommentDto getParentLogComment() {
        return parentLogComment;
    }

    public void setParentLogComment(LogCommentDto parentLogComment) {
        this.parentLogComment = parentLogComment;
    }
}
